package com.friday.bo.impl;

import java.util.List;

import com.friday.bo.MessageBo;
import com.friday.dao.EmployeeDao;
import com.friday.dao.MessageDao;
import com.friday.dao.impl.EmployeeDaoImpl;
import com.friday.dao.impl.MessageDaoImpl;
import com.friday.po.Employee;
import com.friday.po.Message;

public class MessageBoImpl implements MessageBo {

	@Override
	public List<Message> getNewMessageByAccount(String account) throws Exception {
		MessageDao msgDao = new MessageDaoImpl();
		EmployeeDao empDao = new EmployeeDaoImpl();
		Employee emp = empDao.queryEmployeesByAccount(account);
		return msgDao.queryNewMessageByReceiver(emp.getId());
	}

	@Override
	public List<Message> getAllMessageByAccount(String account) throws Exception {
		MessageDao msgDao = new MessageDaoImpl();
		EmployeeDao empDao = new EmployeeDaoImpl();
		Employee emp = empDao.queryEmployeesByAccount(account);
		return msgDao.queryMessageByReceiver(emp.getId());
	}

	@Override
	public Message readMessage(String messageId) throws Exception {
		
		MessageDao msgDao = new MessageDaoImpl();
		
		Message msg = msgDao.queryMessageById(messageId);
		
		msg.setState(1);
		
		msgDao.updateMessage(msg);
		
		return msg;
	}

}
